package cn.com.sina.finance.todolist.net;

import androidx.annotation.NonNull;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 *
 *
 * @author yuebo
 * @date 2024/10/21
 */
public class HostInterceptor implements Interceptor {

    @NonNull
    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {
        Request request = chain.request();
        HttpUrl.Builder urlBuilder = request.url().newBuilder();
        // 替换原来url中的地址
        urlBuilder.host(getHost());
        urlBuilder.port(8080);
        // 构建新的Request对象
        Request newRequest = request.newBuilder().url(urlBuilder.build()).build();
        // 继续处理网络请求
        return chain.proceed(newRequest);
    }

    private static @NonNull String getHost() {
        return "10.222.38.23";
    }
}
